{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "initial centroids are: [[1.93794984e+01 2.39760000e-03 4.89165600e-03 2.94206000e-02\n",
      "  4.62957989e+00 6.83562880e-02 3.05161732e+01 2.13904278e-02\n",
      "  4.39415266e+01]\n",
      " [2.60868530e+01 3.59640000e-01 6.82926000e+00 4.10520000e-02\n",
      "  3.75667740e+00 3.87200000e-02 4.55400000e+00 8.00016000e+00\n",
      "  4.52029166e+01]\n",
      " [1.98661419e+01 0.00000000e+00 9.67213800e+00 5.29570800e+00\n",
      "  4.26223440e+00 1.85856000e-01 1.51680000e+01 4.85724000e-01\n",
      "  4.53232901e+01]\n",
      " [1.87788008e+01 4.37562000e-01 1.19273820e+01 3.42100000e-02\n",
      "  1.24522578e+01 2.16832000e-01 6.78600000e+00 6.70013400e+00\n",
      "  4.32476426e+01]]\n",
      "group result iteration 1 [504. 138. 202. 128.]\n",
      "group result iteration 2 [504. 141. 200. 127.]\n",
      "group result iteration 3 [504. 141. 200. 127.]\n",
      "Wkmeans Finish!\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEGCAYAAABiq/5QAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/d3fzzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAo9klEQVR4nO3dfZxVZb338c9vxmFGGJQnIwIBPYGI7AEEJaEQFFHT1CwzK4+lZR1NLU96m92vW6z7lKWePHoyKk0wzUTTO/X4RJzZ6l3nRkEEeRBJQ0A5iiPgDDrADL/7j7X2PDEPa2DWrL1nfd+v137tvdZeD799Mfz22td1resyd0dERNKjKOkARESkeynxi4ikjBK/iEjKKPGLiKSMEr+ISMockHQAUQwaNMhHjhyZdBj7ZceOHfTp0yfpMPKGyqORyqI5lUdz+1MeS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VcXUqVMpKSmhtraWz3zmMw3lks1mG34xtBUfBF2Lo/6fijvxT3P3t8LkvtDMXom6Y/gl8WuAyZMn+76OTjdlCixb1jvx0f404mBzPaU81qxZ0/AfsKO20cceC6p3mrY9lZcbN964ky98oXc7e/Zq853S0lJKS0v3SgLuzuLFizkwV9/ZZPvy8vKG7UtKSigrKwOgqKioYX3v3r056KCDGpaLi4vp3bt3s+U+ffqwc+dODjjgAPr27duwf24bM2t2LoADDzyQXr16NawrKytrWM59luLiYp566imeffZZHnnkEW666SZWrVq112e95ppruPLKKznjjDPIZrPMmTOn4TitfcbOllVTuc/bct9cH/q+ffty0EEH4e707duXn/70p5x00kk8+uijrF+/nhkzZtC3b1/KysqaxVZaWkqvXr0oKyujpKSk1XLZs2dPh/Hl9pk4cWK72+TEWsfv7m+Fz+8ADwPHAm+b2RCA8PmdOGPIZOD11/fu5SPS3XJtT+XlYBY8T5kCs2fveyX/iSeeyIIFC6iqqgLgvffeA2D27Nn8+7//e8N2L3XQpa1v375tNqoCTJ8+nXvvvReAV199lQ0bNnDEEUe0uc0TTzzB1q1799mYMmUK2WyWqqoqdu/ezQMPPLDXNnv27GHjxo3MnDmTn/3sZ2zbto2ampq9Yty+fTtDhw4FYP78+e1+Pti/spo9ezZz586lrq6u2b5taRrbvHnzOozt2GOP5ZlnnmHr1q3U1dXxxz/+seG9E044oVP/llHElvjNrI+Z9c29BmYDK4FHgAvCzS4A/hRXDAAVFUFt6qpka3pEKC4ObiK87z744Q+D5/29qfCoo47iBz/4Accffzzjx4/nyiuvBILG0SVLllBRUcHYsWOZO3duu8cZOHAg06ZNY9y4cVx11VV7vX/JJZdQX19PJpPh3HPPZd68ec2qcACuu+46nn32WY4++miefvpphg8fvtdxhgwZwpw5czjuuOOYNWsWRx999F7b1NfX85WvfKWhIfm73/0u/fr14zOf+QwPP/xwQ+PunDlzOOecc/jUpz7FoEGDYi2rr3/96wwfPryhYfj3v/99u+e6+uqr+f73v8+0adOoj9B6P3ToUK699lqm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2TfugYIBsOIlYH3Eswlv6+mg1cE8aQBcqA4eF7C909Ny67AT82sxXAnwnmchjcwbE/CfwOwN1fAd4Acol/kbtvd/dagnGBRuzHZ5ACpSt+yRe3EIzTcleTdXWEFyfhwF29mry3s8nrPU2W99D877rlmCROkEwvc/enmr5hZjMIhkZujXUQf2cZ8Dl3X9sihiktYvgycAgwyd13hyObdjQlYXuxNi23epQDUklX/JIXwivcBQQNpTnrCapWIBirvWQfDn2OmRWF9f6HA2uBp4B/CofLxsxGW8cToCwGjjezQWHD73nAM52Ioxro22T5KeCy8AsNM5vYxn4HE8xhsDusq89dobc8XlPPEnxhEFbxDCf43CKAEr/kl5uBpr17fkOQbJ8HWl4JR7WWIEE/AXwrrOK4g6Ca48WwQfRXdHDlG85+9H2gElgOvOjunRkitxIYm2vcBX5E8EW2IozhR23sdy8w2cyWECTzV8J4qgjaJla2bFQGbgeKzexl4H7gq2GVmAig0TlFRFJHV/wiIimjxC8ikjJK/CIiKaPELyKSMkr8IiIpo8QvIpIySvwiIinz/wE4CSA/m2BVuQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "****************************** model performance ******************************\n",
      "Homogeneity Score         (均一性):  0.730800911595108\n",
      "Completeness Score        (完整性):  0.707588179192041\n",
      "V-Measure Score           (V量):  0.719007241781128\n",
      "Adjusted Rand Score       (调整后兰德指数):  0.6836460449215455\n",
      "Adjusted Mutual Info Score(调整后的共同信息):  0.717900397310143\n",
      "Calinski Harabasz Score:  (方差比指数)  754.1580114323565\n",
      "Silhouette Score          (轮廓分数):  0.6143388822782253\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "from wkmeans_class import *\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "wkmeans=wkmeans()\n",
    "orig_data = pd.read_excel('test4.xlsx')\n",
    "orig_data.dropna(inplace=True)\n",
    "\n",
    "x_orig_data = orig_data.drop('TRUE VALUE',axis=1)\n",
    "y_label = orig_data['TRUE VALUE']\n",
    "\n",
    "x_data = np.array(x_orig_data)\n",
    "        \n",
    "feature= pd.read_excel('feature.xlsx') # read initial features from feature.xlsx file\n",
    "feature = np.array(feature)\n",
    "n_iters = feature[0,0]\n",
    "n_clusters = feature[0,1]\n",
    "centroids = wkmeans.plus_plus(x_data, n_clusters)\n",
    "dist = np.zeros((x_data.shape[0],n_clusters), dtype=float)\n",
    "\n",
    "print(\"initial centroids are:\",centroids)\n",
    "\n",
    "w = wkmeans.CalcWeight(x_data)\n",
    "tol=1e-7\n",
    "count=0\n",
    "C = np.zeros(n_iters)\n",
    "\n",
    "for i in range(n_iters):\n",
    "    count+=1\n",
    "    group= np.zeros(n_clusters)\n",
    "    old_centroids=centroids.copy()\n",
    "    for j in range(x_data.shape[0]):\n",
    "        distance = np.power(x_data[j,:]-centroids, 2)  \n",
    "        distance = np.sum(w*distance, axis=1)\n",
    "        distance = np.sqrt(distance) \n",
    "        dist[j,:] = distance\n",
    "    idx = np.argmin(dist, axis=1)   # predicted group index\n",
    "\n",
    "    for k in range(n_clusters):\n",
    "        d = x_data[idx==k, :]\n",
    "        group[k]=d.shape[0]\n",
    "        centroids[k,:] = np.mean(d, axis=0)\n",
    "    print('group result iteration', count, group)   # group number after each iterration\n",
    "    centroid_change=wkmeans.sqrsum(centroids - old_centroids)\n",
    "    C[i]=centroid_change\n",
    "    if centroid_change <= tol:\n",
    "            break\n",
    "print(\"Wkmeans Finish!\")\n",
    "\n",
    "plt.plot(np.arange(n_iters)+1, C, color='blue', marker='o', markersize=5, label='centroid distance change')\n",
    "plt.grid(True)\n",
    "plt.xlabel(\"Number of iteration\")\n",
    "plt.ylabel(\"centroid distance change\")\n",
    "plt.legend(loc='best')\n",
    "plt.show()\n",
    "\n",
    "print(wkmeans.get_marks(x_data, y_label, idx))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
